package top.lilele.adminSystem.config;

import cn.dev33.satoken.stp.StpInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import top.lilele.adminSystem.dto.UserMenuDto;
import top.lilele.adminSystem.service.AdminResourceService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * sa-token权限集合
 *
 * @author lilele
 */
@Component
@Slf4j
public class PermissionsConfig implements StpInterface {
    @Resource
    AdminResourceService adminResourceService;

    @Value("${account.salt}")
    String salt;

    @Value("${account.defaultPassword}")
    String defaultPassword;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 获取当前用户的所有权限
        List<UserMenuDto> list1 = adminResourceService.selectApiResourceByUserId(loginId.toString());
        List list = new ArrayList();
        list1.forEach(adminResourceEntity -> list.add(adminResourceEntity.getName()));
        log.info("权限list集合 {}", list);
        return list;
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
